#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 1e2 + 10;
int a[N], b[N], dp[N];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		memset(b, 0, sizeof b);
		memset(a, 0, sizeof a);
		memset(dp, 0, sizeof dp);
		for (int i = 1; i <= n; i++)
			a[i] = ceil((double)i / k);
		for (int i = 1; i <= n; i++)
			b[i] = ceil((double)(n - i + 1) / k);
		int res = 0;
		for (int i = 1; i <= n; i++)
		{
			if (a[i] > res)
			{
				dp[i] = 1;
				res++;
			}
		}
		res = 0;
		for (int i = n; i > 0; i--)
		{
			if (b[i] > res)
			{
				dp[i] = 1;
				res++;
			}
			res += dp[i];
		}
		res = 0;

		for (int i = 1; i <= n; i++)
			if (dp[i]) res++;

		cout << res << endl;
	}
}